package fulbitofacil.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fulbitofacil.negocio.ComentarioNegocio;
import fulbitofacil.negocio.PublicidadNegocio;

/**
 * Servlet implementation class ComentarioServlet
 */
@WebServlet("/ComentarioServlet")
public class ComentarioServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ComentarioServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String parametro = request.getParameter("param");
		if(parametro.equals("listarComentarios"))
			  listarComentarios(request,response);
		else if(parametro.equals(request.getParameter("param")))
			registraComentario(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	private void listarComentarios(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("entro a listar comentarios");
		ComentarioNegocio servicio = new ComentarioNegocio();	
		int idCancha = Integer.parseInt(request.getParameter("idCancha"));
		List conts = servicio.listarComentarios(idCancha);				
		request.setAttribute("lista",conts);
		request.getRequestDispatcher("listarComentarios.jsp").forward(request, response);
	}
	
	private void registraComentario(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ComentarioNegocio negocio = new ComentarioNegocio();
		
		
		//negocio.agregarComentario(fecha, hora, descripcion, calificacion, idCancha, idCliente, idComentarioPadre);
	}
	

}
